home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / Packet.h < prev    next >
C/C++ Source or Header  |  2000-07-15  |  5KB  |  232 lines

  1.  
  2. #if !defined(AFX_PACK_H__A2D4CDEA_22B4_11D4_ACF2_00A0CC533D52__INCLUDED_)
  3. #define AFX_PACK_H__A2D4CDEA_22B4_11D4_ACF2_00A0CC533D52__INCLUDED_
  4.  
  5. #if _MSC_VER > 1000
  6. #pragma once
  7. #endif // _MSC_VER > 1000
  8.  
  9. #pragma pack (push, 1)
  10.  
  11. union IP            // Size 4     // tried to imitate winsock structure in_addr, while still being compatible
  12. {
  13.       struct { u_char s_b1,s_b2,s_b3,s_b4; }    ;//S_un_b;
  14.       struct { u_short s_w1,s_w2; }                ;//S_un_w;
  15.       struct {BYTE a, b, c, d;}                    ;//old_IP;
  16.       u_long                                   S_addr;
  17. };
  18.  
  19. struct XWORD                // Size 4
  20. {    
  21.     BYTE a;                        // 0
  22.     BYTE b;                        // 1
  23.     BYTE c;                        // 2
  24.     BYTE d;                        // 3
  25. };
  26.  
  27. struct packet_Header        // Size 23
  28. {
  29.     GUID Guid;                    // 0 - 15
  30.  
  31.     BYTE Function;                // 16
  32.     BYTE TTL;                    // 17
  33.     BYTE Hops;                    // 18
  34.  
  35.     XWORD Payload;                // 19 - 22
  36. };
  37.  
  38. struct packet_Ping            // Size 23
  39. {
  40.     packet_Header Header;        // 0 - 22
  41. };
  42.  
  43. struct packet_Pong            // Size 37
  44. {
  45.     packet_Header Header;        // 0 - 22
  46.  
  47.     WORD Port;                    // 23 - 24
  48.     IP Host;                    // 25 - 28
  49.     XWORD FileCount;            // 29 - 32
  50.     XWORD FileSize;                // 33 - 36
  51. };
  52.  
  53. struct packet_Push            // Size 47
  54. {
  55.     packet_Header Header;        // 0 - 22;
  56.  
  57.     GUID ClientID;                // 23 - 38
  58.     XWORD Index;                // 39 - 42
  59.     IP Host;                    // 43 - 46
  60.     WORD Port;                    // 47 - 48
  61. };
  62.  
  63. struct packet_Query            // Size 25+
  64. {        
  65.     packet_Header Header;        // 0 - 22
  66.  
  67.     WORD Speed;                    // 23 - 24
  68.     // Search                    // 25+
  69. };
  70.  
  71. struct packet_QueryReply    // Size 34+
  72. {
  73.     packet_Header Header;        // 0 - 22
  74.  
  75.     byte TotalHits;                // 23
  76.     WORD Port;                    // 24 - 25
  77.     IP Host;                    // 26 - 29
  78.     XWORD Speed;                // 30 - 33
  79.     // QueryReplySet            // 34+
  80. };
  81.  
  82. struct packet_QueryReplySet    // Size 8+
  83. {
  84.     XWORD Index;                // 0 - 3
  85.     XWORD Size;                    // 4 - 7
  86.     //LPSTR FileName                    // 8+    
  87. };
  88.  
  89. IP      StrtoIP(CString in);
  90. CString IPtoStr(IP in);
  91. CString WrdtoStr(WORD in);
  92. CString DWrdtoStr(DWORD in);
  93.  
  94. struct QueryItem
  95. {
  96.     QueryItem()        // zero all the variables
  97.     { subsearchMatch = true; excluded = false; Host.S_addr = Size = BytesCompleted = Speed = Index = Handle = IconIndex = SortBy = Reverse = Port = 0;    }
  98.     
  99.     CString FileName;            // path to remote file
  100.     CString LocalFileName;        // local file name in save directory.  (for *[2].*, *[3].*, etc)
  101.     CString FileType;
  102.     CString Status;
  103.     
  104.     IP    Host;
  105.     WORD  Port;
  106.     DWORD Size;
  107.     DWORD BytesCompleted; // Needed for pause / resume of a file
  108.     
  109.     DWORD Speed;
  110.     DWORD Index;
  111.  
  112.     int   Handle;
  113.     char  TransferType;  // 'D' for download, 'U' for upload, its stupid i know, 'bandaid'
  114.  
  115.     int   IconIndex;
  116.  
  117.     GUID  Guid;
  118.  
  119.     bool subsearchMatch; // if the search result matches any subsearch
  120.     bool excluded; // if the search result should be excluded due to user typing in exclude box
  121.  
  122.     static int    SortBy;
  123.     static int    Reverse;
  124.  
  125.     inline int operator < (struct QueryItem& first)
  126.     {
  127.         bool bResult;
  128.         switch (SortBy)
  129.         {
  130.         case 3: // Host
  131.             {    
  132.                 if( IPtoStr(first.Host) > IPtoStr(Host) )
  133.                     bResult = 1;
  134.                 else if( IPtoStr(first.Host) == IPtoStr(Host) )
  135.                     bResult = (first.FileName > FileName);
  136.                 else
  137.                     bResult = 0;
  138.  
  139.                 break;
  140.             }
  141.         case 1:    // Size
  142.             {                
  143.                 if(first.Size > Size)
  144.                     bResult = 1;
  145.                 else if(first.Size == Size)
  146.                     bResult = (first.FileName > FileName);
  147.                 else
  148.                     bResult = 0;
  149.  
  150.                 break;
  151.             }
  152.         case 4: // Speed
  153.             {
  154.                 if(first.Speed > Speed)
  155.                     bResult = 1;
  156.                 else if(first.Speed == Speed)
  157.                     bResult = (first.FileName > FileName);
  158.                 else
  159.                     bResult = 0;
  160.  
  161.                 break;
  162.             }
  163.         case 2: // File Type
  164.             {
  165.                 if( _stricmp( first.FileType, FileType ) > 0 )
  166.                     bResult = 1;
  167.                 else if(first.FileType == FileType)
  168.                     bResult = (_stricmp( first.FileName, FileName ) > 0 );
  169.                 else
  170.                     bResult = 0;
  171.  
  172.                 break;
  173.             }
  174.         case 0:    // Filename
  175.         default:
  176.             {
  177.                 bResult = ( _stricmp( first.FileName, FileName ) > 0  );
  178.                 break;
  179.             }
  180.         }
  181.  
  182.         return (Reverse ? !bResult : bResult);
  183.     };
  184. };
  185.  
  186. struct SharedFile
  187. {
  188.     CString FileDir;
  189.     CString FileName;
  190. };
  191.  
  192. struct BlockedSearch
  193. {
  194.     CString Name;
  195.     char    Permis;
  196. };
  197.  
  198. XWORD flipX(XWORD);
  199. WORD  flipW(WORD in);
  200. XWORD makeX(DWORD);
  201. DWORD makeD(XWORD);
  202.  
  203. CString CommaIze(CString in);
  204. CString GetIconDesc(CString);
  205.  
  206. //    HICON GetIconFromName(CString File);    // Deprecated, use the next two functions since they keep a cache of icons
  207. int GetIconIndexFromName (const CString& file);
  208. CImageList* GetSharedImageList ();
  209.  
  210. bool SearchMatch(const char* _psz_search_for, const char* _psz_string_to_search);
  211.  
  212. union FOUR64BIT
  213. {
  214.     DWORD64 dw64;
  215.  
  216.     struct
  217.     {
  218.         short i4;
  219.         short i3;
  220.         short i2;
  221.         short i1;
  222.     };
  223. };
  224.  
  225. DWORD64 util_GetVersionNumber(LPCTSTR lpstrFilename);
  226.  
  227.  
  228. #pragma pack (pop)
  229.  
  230. #endif // !defined(AFX_PACK_H__A2D4CDEA_22B4_11D4_ACF2_00A0CC533D52__INCLUDED_)
  231.  
  232.